/*
 * Copyright 2008 Johnny Jian
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.getris.panel

import groovy.swing.SwingBuilder
import static java.awt.Color.*
import java.awt.Font
import javax.swing.Box

class InfoPanel extends FramePanel {

	def scoreLabel
	def score
	def level
	def lines

	InfoPanel(tetris) {
		def labelFont = new Font('SansSerif', Font.PLAIN, 18)
		def scoreFont = new Font('SansSerif', Font.BOLD, 20)

		def swing = new SwingBuilder()
		add(swing.box(Box.createVerticalBox()) {
			scoreLabel = label(alignmentX: CENTER_ALIGNMENT, foreground: WHITE, font: labelFont)
			score = label(alignmentX: CENTER_ALIGNMENT, foreground: YELLOW, font: scoreFont)
			widget(Box.createVerticalStrut(5))
			level = label(alignmentX: CENTER_ALIGNMENT, foreground: WHITE, font: labelFont)
			lines = label(alignmentX: CENTER_ALIGNMENT, foreground: WHITE, font: labelFont)
		})

		tetris.addChangingObserver({ o, game ->
			scoreLabel.text = 'Score'
			score.text = "$game.scoreKeeper.score"
			level.text = "Level $game.scoreKeeper.level"
			lines.text = "$game.scoreKeeper.lines Lines"
		} as Observer)
	}

}
